package com.doudoukeji.service.Bean;

import android.content.Context;

import com.doudoukeji.service.Utils.SharedPreferencesUtils;

import org.apache.commons.lang3.StringUtils;

/**
 * @version 2.0
 * @类描述： Token
 * @项目名称：ddgh
 * @类名称： Token
 * @包名称： com.doudoukeji.service.Bean
 * @创建人：张强 boy
 * @创建时间：2016/3/14 15:54
 * @修改人：
 * @修改时间：2016/3/14 15:54
 * @修改备注： new parent class(用一句话描述修改了什么)
 */

public class Token {


    private static String hosVersion;//医院版本号
    private static String servVersion;//服务项目版本号
    private static String id;//用户
    private static String phone;//用户手机号
    private static String name;//工程新一用户名称
    private static String hospitals;//医院id
    private static String services;//医院名称
    private static String token;//唯一识别码

    public static String HOSVERSION="hosVersion";//医院版本号
    public static String SERVVERSION="servVersion";//服务项目版本号
    public static String ID="id";//用户
    public static String PHONE="phone";//用户手机号
    public static String NAME="name";//工程新一用户名称
    public static String HOSPITALS="hospitals";//医院id
    public static String SERVICES="services";//医院名称
    public static String TOKEN="token";//唯一识别码

    public static Context mcontext;


    /**
     * 注销Token
     */
    public static void logout() {
        Token.hosVersion="";//医院版本号
        Token.servVersion="";//服务项目版本号
        Token.id="";//用户
        Token.setId("");
        Token.phone="";//用户手机号
        Token.setPhone("");
        Token. name="";//工程新一用户名称
        Token.setName("");
        Token.hospitals="";//医院id
        Token.services="";//医院名称
        Token.token="";//唯一识别码
        Token.setToken("");
    }


    public static Context getMcontext() {
        if (Token.mcontext != null) {
            return Token.mcontext;
        }
        return com.sanhai.android.service.Token.getContext();
    }

    public static void setMcontext(Context mcontext) {
        Token.mcontext = mcontext;
    }

    public static String getHosVersion() {
        if (StringUtils.isNotBlank(hosVersion)) {
            return hosVersion;
        } else {
            hosVersion = SharedPreferencesUtils.getParam(mcontext, Token.HOSVERSION, "0");
            return hosVersion;
        }
    }

    public static void setHosVersion(String hosVersion) {
        Token.hosVersion = hosVersion;
        SharedPreferencesUtils.setParam(mcontext, Token.HOSVERSION, hosVersion);
    }

    public static String getServVersion() {
        if (StringUtils.isNotBlank(servVersion)) {
            return servVersion;
        } else {
            servVersion = SharedPreferencesUtils.getParam(mcontext, Token.SERVVERSION, "0");
            return servVersion;
        }
    }

    public static void setServVersion(String servVersion) {
        Token.servVersion = servVersion;
        SharedPreferencesUtils.setParam(mcontext, Token.SERVVERSION, servVersion);
    }

    public static String getId() {
        if (StringUtils.isNotBlank(id)) {
            return id;
        } else {
            id = SharedPreferencesUtils.getParam(mcontext, Token.ID, "");
            return id;
        }
    }

    public static void setId(String id) {
        Token.id = id;
        SharedPreferencesUtils.setParam(mcontext, Token.ID, id);
    }

    public static String getPhone() {
        if (StringUtils.isNotBlank(phone)) {
            return phone;
        } else {
            phone = SharedPreferencesUtils.getParam(mcontext, Token.PHONE, "");
            return phone;
        }
    }

    public static void setPhone(String phone) {
        Token.phone = phone;
        SharedPreferencesUtils.setParam(mcontext, Token.PHONE, phone);
    }

    public static String getName() {
        if (StringUtils.isNotBlank(name)) {
            return name;
        } else {
            name = SharedPreferencesUtils.getParam(mcontext, Token.NAME, "");
            return name;
        }
    }

    public static void setName(String name) {
        Token.name = name;
        SharedPreferencesUtils.setParam(mcontext, Token.NAME, name);
    }

    public static String getHospitals() {
        if (StringUtils.isNotBlank(hospitals)) {
            return hospitals;
        } else {
            hospitals = SharedPreferencesUtils.getParam(mcontext, Token.HOSPITALS, "");
            return hospitals;
        }
    }

    public static void setHospitals(String hospitals) {
        Token.hospitals = hospitals;
        SharedPreferencesUtils.setParam(mcontext, Token.HOSPITALS, hospitals);
    }

    public static String getServices() {
        if (StringUtils.isNotBlank(services)) {
            return services;
        } else {
            services = SharedPreferencesUtils.getParam(mcontext, Token.SERVICES, "");
            return services;
        }
    }

    public static void setServices(String services) {
        Token.services = services;
        SharedPreferencesUtils.setParam(mcontext, Token.SERVICES, services);
    }

    public static String getToken() {
        if (StringUtils.isNotBlank(token)) {
            return token;
        } else {
            token = SharedPreferencesUtils.getParam(mcontext, Token.TOKEN, "");
            return token;
        }
    }

    public static void setToken(String token) {
        Token.token = token;
        SharedPreferencesUtils.setParam(mcontext, Token.TOKEN, token);
    }
}
